!function (t) {
    function i(s) {
        if (e[s]) return e[s].exports;
        var n = e[s] = {
            exports: {},
            id: s,
            loaded: !1
        };
        return t[s].call(n.exports, n, n.exports, i), n.loaded = !0, n.exports
    }
    var e = {};
    return i.m = t, i.c = e, i.p = "./", i(0)
}([function (t, i, e) {
    e(1)
},  function (t, i) {
    Vue.component("pop-tree-organization-component", {
        template:'<div class="pop-panel" v-bind:class="{\'show\':this.show}"><div class="pop-box"><div class="pop-title">选择机构<a class="win_close_btn" @click="close()"><i class="fa fa-fw fa-close"></i></a></div><div class="pop-content"><div style="height:435px;width:100%;overflow-y:scroll;overflow-x:auto;"><ul id="treeDemo" class="ztree"></ul></div><div class="box-footer"><button type="button" class="btn btn-info btn-sm" @click="selectOrg()" style="width:120px;float:left;">{{button}}</button><button type="button" class="btn  btn-default btn-sm" style="width:120px;float:left;margin-left:15px;" @click="close()">取消</button></div></div></div><div class="bg"></div></div>',
        data: function () {
            return {
                show: !1,
                title:'选择机构',
                button:'确认选择',
                selectNodes:[],
            }
        },
        events: {
            'openTreeOrganizationWin': function () {
                var i = this;
                i.data_init();
            },
        },
        methods: {
            data_init: function () {
                this.selectNodes=[],this.show = !0;
                this.getTree();
            },
            getTree:function () {
                var t = this;
                postMsg(root+"/organization/tree", {s:true}, function(i) {
                    var setting = {
                        callback:{
                            onClick:function (event, treeId, treeNode, clickFlag) {
                                tree.checkNode(treeNode, clickFlag, clickFlag);
                            },
                            onCheck:function (event, treeId, treeNode) {
                                // console.log(treeNode.checked);
                                if (treeNode.checked == true) {
                                    t.selectNodes.push(treeNode);
                                } else {
                                    for (var i = 0; i<t.selectNodes.length; i++) {
                                        if (t.selectNodes[i].id == treeNode.id) {
                                            t.selectNodes.splice(i, 1);
                                        }
                                    }
                                }
                            }
                        },
                        check: {
                            enable: true,
                            chkboxType:{ "Y":"", "N":""},
                            chkStyle: "checkbox"
                        }
                    };
                    var tree = $.fn.zTree.init($("#treeDemo"), setting, i);
                });
            },
            selectOrg:function () {
                var t = this;
                if (t.selectNodes.length == 0) {
                    layer.alert('请选择一个机构');
                } else {
                    // console.log(t.selectNodes);
                    var organization_ids = "";
                    var organization_names = "";
                    for (var i=0; i<t.selectNodes.length; i++) {
                        var node = t.selectNodes[i];
                        // organization_ids.push(node.id);

                        if (organization_ids != "") {
                            organization_ids += ",";
                        }
                        organization_ids += node.id;


                        if (organization_names != "") {
                            organization_names += ",";
                        }
                        organization_names += node.name;
                    }
                    t.$dispatch("selectOrg", {organization_ids:organization_ids, organization_names:organization_names});
                    t.close();
                }
            },
            close: function () {
                var t = this;
                t.show = !1;
            }
        }
    })
}]);